Skip to content

Validate PsrpOperator parameters after rendering#70347

Open
1fanwang wants to merge 6 commits into
apache:mainfrom
1fanwang:fix-psrp-init
Open

Validate PsrpOperator parameters after rendering#70347
1fanwang wants to merge 6 commits into
apache:mainfrom
1fanwang:fix-psrp-init

Conversation

@1fanwang

Copy link
Copy Markdown
Contributor

command, powershell, cmdlet, arguments and parameters are template fields, so they are rendered after __init__ runs. The constructor validated their combination (exactly one of command/powershell/cmdlet; arguments/parameters only with powershell/cmdlet) and derived task_id from cmdlet — all reading the un-rendered Jinja expressions. Move the validation into execute(), which runs after rendering.

Breaking change (flagged for maintainers): this drops the cmdlet-derived task_id default. That default read the cmdlet template field at construction, before super().__init__, and task_id is identity — so it is the one piece that can't move to execute(). Pass task_id explicitly when using cmdlet. If you'd rather keep the convenience, the alternative is to leave PsrpOperator on the exemption list until the check can sanction a task_id-from-template default; I went with the removal to clear the entry, but happy to revert that part.

related: #70296

Testing Done

test_no_command_or_powershell now asserts the ValueError surfaces from execute(); it fails on the pre-fix source (the constructor raised first) and passes after. Dropped test_cmdlet_task_id_default (behaviour removed) and passed task_id explicitly in the two securestring tests. test_psrp.py: 33 passed. validate_operators_init.py on the operator exits 0.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: GitHub Copilot CLI following the guidelines

command, powershell, cmdlet, arguments and parameters are template fields,
rendered after __init__ runs. The constructor validated their combination and
derived task_id from cmdlet, all reading the un-rendered Jinja expressions. Move
the validation into execute(), which runs after rendering.

This drops the cmdlet-derived task_id default (a construction-time read of a
template field that cannot move): task_id must now be passed explicitly when
using cmdlet.

related: apache#70296
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang marked this pull request as draft July 24, 2026 05:47
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang marked this pull request as ready for review July 24, 2026 06:23
@shahar1 shahar1 removed the backport-to-v3-3-test Backport to v3-3-test label Jul 24, 2026
1fanwang added 3 commits July 24, 2026 11:32
Signed-off-by: 1fanwang <1fannnw@gmail.com>

# Conflicts:
#	scripts/ci/prek/validate_operators_init_exemptions.txt
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
command is a template field, so validating it in __init__ checked the raw
Jinja expression, not the rendered value. Add a test that renders a command
resolving to an empty string, then executes: it fails on the pre-fix source
(the empty command slips past __init__ and reaches execution) and passes with
validation in execute().

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants